/**
 * Created by haocongshun on 2016/9/14.
 */
var contextPath = "/";
$(function () {
    contextPath += window.location.pathname.split("/")[1];
    $("#toptitle").html("我的留言");
    init();
});
function init() {
    var url = contextPath + "/message/leaveMessage.wm";
    var data = {};
    if(location.search.split("&")[0].substring(1)=="tea"){
        data.flag="tea_to_stu";
    }else {
        data.flag="stu_to_tea";
    }
    $.post(url,data,function (result) {
        var newHtml = "";
        if(data.flag=="tea_to_stu"){
            for(var i = 0;i < result.tea_to_stu.length;i++){
                newHtml+="<div class='panel king-panel1 m25'>"+
                    "<div class='panel-heading king-panel-head1 king-panel-top1'>"+
                    "<h3 class='panel-title'>留言</h3>"+
                    "</div>"+
                    "<div class='panel-body'>"+
                    "<p>"+
                    result.tea_to_stu[i].aStudent.student_name+
                    "同学给你留言了！"+
                    "<a href='"+contextPath+"/talk/leaveMessage.jsp?tea&to="+result.tea_to_stu[i].student_id+"'>【点击查看】</a>"+
                    "</p>"+
                    "<p class='messageDate'>"+result.tea_to_stu[i].leaveMessage_date+"</p>"+
                    "</div>"+
                    "</div>";
            }
        }
        if(data.flag=="stu_to_tea"){
            for(var i = 0;i < result.stu_to_tea.length;i++){
                newHtml+="<div class='panel king-panel1 m25'>"+
                    "<div class='panel-heading king-panel-head1 king-panel-top1'>"+
                    "<h3 class='panel-title'>留言</h3>"+
                    "</div>"+
                    "<div class='panel-body'>"+
                    "<p>"+
                    result.stu_to_tea[i].aTeacher.teacher_name+
                    "老师给你留言了！"+
                    "<a href='"+contextPath+"/talk/leaveMessage.jsp?stu&to="+result.stu_to_tea[i].teacher_id+"'>【点击查看】</a>"+
                    "</p>"+
                    "<p class='messageDate'>"+result.stu_to_tea[i].leaveMessage_date+"</p>"+
                    "</div>"+
                    "</div>";
            }
        }
        if(newHtml==""||newHtml==null){
            $("#leaveMessage").html("<div class='king-notice-box king-notice-sad'> <p class='king-notice-text'>还没有人给你留言！ </p> </div>");
        }
        else {
            $("#leaveMessage").html(newHtml);
        }
    },"json");
}